package com.itboye.sunsun.uesrinfo;

import com.itboye.sunsun.application.App;
import com.itboye.sunsun.beans.TieZiQuanXianBean;
import com.itboye.sunsun.beans.TieZiQuanXianBean.Group;
import com.itboye.sunsun.constants.SPContants;
import com.itboye.sunsun.utils.SPUtils;

import u.aly.be;

/**
 * 帖子相关用户信息管理
 * @author 64
 *
 */
public class TieZiQuanXianManager {

//	private static final String fileName="tiezi_user_info";
	private static TieZiQuanXianBean bean;
	public static void setUserInfo(TieZiQuanXianBean bean){
//		Group group=bean.getGroup();
//		if (group!=null) {
//			SPUtils.put(App.ctx,"Adminid", fileName,group.getAdminid()  );
//			SPUtils.put(App.ctx,"uid", fileName,bean.getId());
//			
//		}
		
		TieZiQuanXianManager.bean=bean;
		
	}
	
//	public static boolean isAdmin(){
//		if (SPUtils.get(App.ctx, fileName, "uid", "")
//				.equals(SPUtils.get(App.ctx, null, SPContants.USER_ID, null))) {
//			return (boolean)SPUtils.get(App.ctx, fileName, "Adminid", false);
//			
//		}
//		return false;
//	}
	
	/**
	 * 是否允许发帖
	 * @param fid
	 * @return
	 */
	public static boolean  canPublishMessage(String fid){
		if (bean==null) {
			return true;
		}
		Group group=bean.getGroup();
		if (group!=null) {
			if (
					(fid.equals(group.getFid()) ||"0".equals(group.getFid()) )
					&& "0".equals(group.getAllowpost())) {
				
				return false;
			}
		}
		
		return true;
	}
	
	
	public static boolean  canAddJingHua(String fid){
		if (bean==null) {
			return false;
		}
		
		Group group=bean.getGroup();
		if (group!=null) {
			if (
					(fid.equals(group.getFid()) ||"0".equals(group.getFid()) )
					&& "1".equals(group.getAllowdigestthread())) {
				
				return true;
			}
		}
		
		return false;
	}
	

	/**
	 * 是否允许删帖
	 * @param fid
	 * @return
	 */
	public static boolean  canDeleteBBs(String fid,String publishUerId){
		String uid=(String) SPUtils.get(App.ctx, null, SPContants.USER_ID, "");
		if (uid.equals(publishUerId)) {
			return true;
		}
		if (bean==null) {
			return false;
		}
		
		Group group=bean.getGroup();
		if (group!=null) {
			if (
					(fid.equals(group.getFid()) ||"0".equals(group.getFid()) )
					&& "1".equals(group.getAllowdelpost())) {
				
				return true;
			}
		}
		
		return false;
	}
	
	/**
	 * 置顶
	 * @param fid
	 * @return
	 */
	public static boolean  canTopBBs(String fid){
		if (bean==null) {
			return false;
		}
		
		Group group=bean.getGroup();
		if (group!=null) {
			if (
					(fid.equals(group.getFid()) ||"0".equals(group.getFid()) )
					&& "1".equals(group.getAllowstickthread())) {
				
				return true;
			}
		}
		
		return false;
	}
}
